package com.rescue.toolbean;

import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

public class JDBC {
	private static String driver="com.mysql.jdbc.Driver";
	static {
		try {
			Class.forName(driver);
		} catch (ClassNotFoundException e) {
			
			e.printStackTrace();
		}
	}
	
	
	//获取数据库连接的方式
	private static Connection conn=null;
	public static Connection getConnection() throws Exception{
		conn=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/rescue?useUnicode=true&characterEncoding=UTF-8", "root", "123456");
		return conn;
		
	}

	//关闭资源的方法
	public static void closeStament(ResultSet rs,PreparedStatement pStmt,Connection conn) {
		if(rs!=null) {
			try {
				rs.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if(pStmt!=null) {
			try {
				pStmt.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if(conn!=null) {
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	
	
}
